import { rateStatus, parentRateStatus } from '@/views/formConst'

// 被评分对象ID evaluation_target_record_id
// 被评分对象标题 evaluation_target_title
// 被评分对象表单ID evaluation_target_form_id
// 被评分对象类型 evaluation_target_form_sub_type
// 被评分对象单位 evaluation_target_org
export function judgesTableColumns() {
  let list = [
    {
      title: '表单名称',
      key: 'name',
      minWidth: 180
    },
    {
      title: '评分阶段',
      key: 'stage',
      width: 120
    },
    {
      title: '被评分对象',
      key: 'evaluation_target_title'
    },
    {
      title: '被评分类型',
      key: 'evaluation_target_form_sub_type'
    },
    {
      title: '推荐单位',
      key: 'org',
      align: '',
      render: (h, params) => {
        return h(
          'Tooltip',
          {
            props: {
              content: this.treeData.find(item => item.orgCode === params.row.evaluation_target_org)?.orgName || '--',
              placement: 'bottom',
              transfer: true
            }
          },
          [
            h(
              'span',
              {},
              this.treeData.find(item => item.orgCode === params.row.evaluation_target_org)?.orgName || '--'
            ) // 实际的DOM内容
          ]
        )
      }
    },
    {
      title: '当前评分周期',
      key: 'period'
    },
    {
      title: '更新时间',
      key: 'updateTime',
      width: 180
    },
    {
      title: '状态',
      render: (h, params) => {
        const rate = rateStatus.find(item => item.key === params.row.status)
        let name = rate?.name || '--'
        let color = rate.color
        return h(
          'div',
          {
            style: {
              display: 'flex',
              'justify-content': 'center',
              'align-items': 'center'
            }
          },
          [
            h('div', {
              style: {
                margin: '4px',
                width: '6px',
                height: '6px',
                'background-color': color /* 圆点颜色 */,
                'border-radius': '50%' /* 圆形 */
              }
            }),
            name
          ]
        )
      }
    },
    {
      title: '评委',
      minWidth: 180,
      key: 'judge'
    },
    {
      title: '得分',
      key: 'score'
      // sortable: 'custom'
    },
    {
      title: '操作',
      align: 'left',
      fixed: 'right',
      width: 150,
      render: (h, params) => {
        return h('RowTools', {
          props: {
            data: [
              {
                type: 'text',
                optType: params.row.createBy === this.userCode ? '' : 'ashing',
                text: params.row.status > 1 ? '查看' : '评分',
                handle: () => {
                  this.editForm(params.row)
                }
              }
            ]
          }
        })
      }
    }
  ]
  return list
}

export function ownerTableColumns() {
  let list = [
    {
      title: '表单名称',
      key: 'formName',
      minWidth: 200,
      tree: true
    },
    {
      title: '评分阶段',
      key: 'stage',
      width: 120
    },
    {
      title: '被评分对象',
      key: 'evaluation_target_title'
    },
    {
      title: '被评分类型',
      key: 'evaluation_target_form_sub_type'
    },
    {
      title: '推荐单位',
      key: 'org',
      width: 150,
      render: (h, params) => {
        return h(
          'Tooltip',
          {
            props: {
              content: this.treeData.find(item => item.orgCode === params.row.evaluation_target_org)?.orgName || '--',
              placement: 'bottom',
              transfer: true
            }
          },
          [
            h('div', this.treeData.find(item => item.orgCode === params.row.evaluation_target_org)?.orgName || '--') // 实际的DOM内容
          ]
        )
      }
    },
    {
      title: '当前评分周期',
      key: 'period',

      width: 120
    },
    {
      title: '更新时间',
      key: 'updateTime',
      width: 180
    },
    {
      title: '状态',
      width: 120,
      render: (h, params) => {
        let rate = {}
        if (params.row.isChild) {
          rate = rateStatus.find(item => item.key === params.row.status)
        } else {
          rate = parentRateStatus.find(item => item.key === params.row.status)
        }
        let name = rate.name || '--'
        let color = rate.color
        return h(
          'div',
          {
            style: {
              display: 'flex',
              'justify-content': 'center',
              'align-items': 'center'
            }
          },
          [
            h('div', {
              style: {
                margin: '4px',
                width: '6px',
                height: '6px',
                'background-color': color /* 圆点颜色 */,
                'border-radius': '50%' /* 圆形 */
              }
            }),
            name
          ]
        )
      }
    },
    {
      title: '评委',
      minWidth: 150,
      key: 'judge'
    },
    {
      title: '得分',
      key: 'score',
      sortable: 'custom'
    },
    {
      title: '是否晋级',
      render: (h, params) => {
        return h('div', {}, params.row.is_passed == 1 ? '是' : params.row.is_passed == 0 ? '否' : '--')
      }
    },
    {
      title: '操作',
      align: 'left',
      fixed: 'right',
      width: 150,
      render: (h, params) => {
        return h('RowTools', {
          props: {
            data: [
              {
                type: 'text',
                text: '查看',
                hidden: !params.row.isChild,
                handle: () => {
                  this.viewForm(params.row)
                }
              },
              {
                type: 'text',
                text: '晋级',
                // 创建人才有晋级按钮,并且没有被晋级过，评分中才显示晋级
                optType: params.row.status === 2 && this.row.data.permission.formCreator ? '' : 'ashing',
                hidden: params.row.isChild || this.onlyView,
                handle: () => {
                  this.pass(params.row)
                }
              }
            ]
          }
        })
      }
    }
  ]
  return list
}

export function ownerSystemOutsideTableColumns() {
  let list = [
    {
      title: '评分阶段',
      key: 'stage',

      width: 120
    },
    {
      title: '表单名称',
      key: 'formName',
      minWidth: 200,
      tree: true
    },
    {
      title: '单位名称',
      key: 'org',
      width: 150,
      render: (h, params) => {
        return h(
          'Tooltip',
          {
            props: {
              content: this.treeData.find(item => item.orgCode === params.row.org)?.orgName || '--',
              placement: 'bottom',
              transfer: true
            }
          },
          [
            h('div', this.treeData.find(item => item.orgCode === params.row.org)?.orgName || '--') // 实际的DOM内容
          ]
        )
      }
    },
    {
      title: '当前评分周期',
      key: 'period',

      width: 120
    },
    {
      title: '评委',
      minWidth: 150,
      key: 'judge'
    },
    {
      title: '更新时间',
      key: 'updateTime',
      width: 180
    },
    {
      title: '状态',
      width: 120,
      render: (h, params) => {
        let rate = {}
        if (params.row.isChild) {
          rate = rateStatus.find(item => item.key === params.row.status)
        } else {
          rate = parentRateStatus.find(item => item.key === params.row.status)
        }
        let name = rate.name || '--'
        let color = rate.color
        return h(
          'div',
          {
            style: {
              display: 'flex',
              'justify-content': 'center',
              'align-items': 'center'
            }
          },
          [
            h('div', {
              style: {
                margin: '4px',
                width: '6px',
                height: '6px',
                'background-color': color /* 圆点颜色 */,
                'border-radius': '50%' /* 圆形 */
              }
            }),
            name
          ]
        )
      }
    },
    {
      title: '得分',
      key: 'score',
      sortable: 'custom'
    },
    {
      title: '是否晋级',
      render: (h, params) => {
        return h('div', {}, params.row.is_passed == 1 ? '是' : params.row.is_passed == 0 ? '否' : '--')
      }
    },
    {
      title: '操作',
      align: 'left',
      fixed: 'right',
      width: 150,
      render: (h, params) => {
        return h('RowTools', {
          props: {
            data: [
              {
                type: 'text',
                text: '查看',
                hidden: !params.row.isChild,
                handle: () => {
                  this.viewForm(params.row)
                }
              },
              {
                type: 'text',
                text: '晋级',
                // 创建人才有晋级按钮,并且没有被晋级过，评分中才显示晋级
                optType: params.row.status === 2 && this.row.data.permission.formCreator ? '' : 'ashing',
                hidden: params.row.isChild || this.onlyView,
                handle: () => {
                  this.pass(params.row)
                }
              }
            ]
          }
        })
      }
    }
  ]
  return list
}

export function systemOutsidetableColumns() {
  let list = [
    {
      title: '评分阶段',
      key: 'stage',

      width: 120
    },
    {
      title: '表单名称',
      key: 'name',
      minWidth: 180
    },
    {
      title: '单位名称',
      key: 'evaluationTargetOrg',
      render: (h, params) => {
        return h(
          'Tooltip',
          {
            props: {
              content: this.treeData.find(item => item.orgCode === params.row.evaluation_target_org)?.orgName || '--',
              placement: 'bottom',
              transfer: true
            }
          },
          [
            h(
              'span',
              {},
              this.treeData.find(item => item.orgCode === params.row.evaluation_target_org)?.orgName || '--'
            ) // 实际的DOM内容
          ]
        )
      }
    },
    {
      title: '当前评分周期',
      key: 'period'
    },
    {
      title: '更新时间',
      key: 'updateTime',
      width: 180
    },
    {
      title: '状态',
      render: (h, params) => {
        const rate = rateStatus.find(item => item.key === params.row.status)
        let name = rate?.name || '--'
        let color = rate.color
        return h(
          'div',
          {
            style: {
              display: 'flex',
              'justify-content': 'center',
              'align-items': 'center'
            }
          },
          [
            h('div', {
              style: {
                margin: '4px',
                width: '6px',
                height: '6px',
                'background-color': color /* 圆点颜色 */,
                'border-radius': '50%' /* 圆形 */
              }
            }),
            name
          ]
        )
      }
    },
    {
      title: '得分',
      key: 'score'
      // sortable: 'custom'
    },
    {
      title: '操作',
      align: 'left',
      fixed: 'right',
      width: 150,
      render: (h, params) => {
        return h('RowTools', {
          props: {
            data: [
              {
                type: 'text',
                optType: params.row.createBy === this.userCode ? '' : 'ashing',
                text: params.row.status > 1 ? '查看' : '评分',
                handle: () => {
                  this.editForm(params.row)
                }
              }
            ]
          }
        })
      }
    }
  ]
  return list
}

export function summaryTableColumns() {
  let list = [
    {
      title: '表单名称',
      key: 'formName',
      minWidth: 180
    },
    {
      title: '评分阶段',
      key: 'showstage',
      width: 120
    },
    {
      title: '被评分对象类型',
      key: 'evaluationTargetFormSubType'
    },
    {
      title: '当前评分周期',
      key: 'period'
    },
    {
      title: '操作',
      align: 'left',
      fixed: 'right',
      width: 200,
      render: (h, params) => {
        return h('RowTools', {
          props: {
            data: [
              {
                type: 'text',
                text: '评委维度',
                handle: () => {
                  this.judgesSummary(params.row)
                }
              },
              {
                type: 'text',
                text: '评分指标维度',
                handle: () => {
                  this.indicatorSummary(params.row)
                }
              }
            ]
          }
        })
      }
    }
  ]
  return list
}
